using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

/// <summary>
/// 控制分数，判断游戏胜利
/// </summary>
public class PointManager : Singleton<PointManager>
{
    /// <summary>
    /// 初始分数
    /// </summary>
    [HideInInspector] public float score = 0;
    /// <summary>
    /// 目标分数
    /// </summary>
    public float targetScore = 100;
    /// <summary>
    /// 每秒增加的分数
    /// </summary>
    public float addScorePerSecond = 10;
    /// <summary>
    /// 多少秒增加一次分数
    /// </summary>
    public float addPerSecond = 3;
    /// <summary>
    /// 碰撞减少的分数
    /// </summary>
    public float minusScore = 20;
    /// <summary>
    /// 击中目标增加的分数
    /// </summary>
    public float addScore = 20;

    private float timer = 0;

    private Text scoreText;

    // Start is called before the first frame update
    void Start()
    {
        scoreText = GetComponent<Text>();
    }

    // Update is called once per frame
    void Update()
    {
        timer += Time.deltaTime;
        if (timer > addPerSecond)
        {
            timer -= addPerSecond;
            score += addScorePerSecond;
        }
        scoreText.text = score.ToString();
        if (score >= targetScore)
        {
            // 判定游戏胜利
            scoreText.text = "胜利";
        }
    }

    /// <summary>
    /// 增加分数的方法
    /// </summary>
    public void AddScore()
    {
        score += addScore;
    }

    /// <summary>
    /// 扣分的方法
    /// </summary>
    public void MinusScore()
    {
        score -= minusScore;
    }
}